/*     */ package com.zimbra.cs.ldap;
/*     */ 
/*     */ import com.google.common.base.Strings;
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class LdapServerConfig
/*     */ {
/*     */   private static final String DEFALT_LDAP_PORT = "389";
/*     */   protected String ldapURLs;
/*     */   protected String adminBindDN;
/*     */   protected String adminBindPassword;
/*     */   protected boolean wantStartTLS;
/*     */   protected LdapConnType connType;
/*     */   protected final boolean sslAllowUntrustedCerts;
/*     */   protected final int connPoolMaxSize;
/*     */   protected final int connPoolTimeoutMillis;
/*     */   protected final boolean connPoolHelathCheckOnCheckoutEnabled;
/*     */   protected final long connPoolHelathCheckBackgroundIntervalMillis;
/*     */   protected final long connPoolHelathCheckMaxResponseTimeMillis;
/*     */   protected final int connectTimeoutMillis;
/*     */   protected final int readTimeoutMillis;
/*     */   protected final boolean isAbandonOnTimeout;
/*     */   
/*     */   public abstract int getConnPoolInitSize();
/*     */   
/*     */   private LdapServerConfig()
/*     */   {
/* 111 */     this.sslAllowUntrustedCerts = LC.ssl_allow_untrusted_certs.booleanValue();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 117 */     this.connPoolMaxSize = LC.ldap_connect_pool_maxsize.intValue();
/*     */     
/* 119 */     this.connPoolTimeoutMillis = LC.ldap_connect_pool_timeout.intValue();
/*     */     
/* 121 */     this.connPoolHelathCheckOnCheckoutEnabled = LC.ldap_connect_pool_health_check_on_checkout_enabled.booleanValue();
/*     */     
/* 123 */     this.connPoolHelathCheckBackgroundIntervalMillis = LC.ldap_connect_pool_health_check_background_interval_millis.longValue();
/*     */     
/* 125 */     this.connPoolHelathCheckMaxResponseTimeMillis = LC.ldap_connect_pool_health_check_max_response_time_millis.longValue();
/*     */     
/*     */ 
/*     */ 
/* 129 */     this.connectTimeoutMillis = LC.ldap_connect_timeout.intValue();
/* 130 */     this.readTimeoutMillis = LC.ldap_read_timeout.intValue();
/* 131 */     this.isAbandonOnTimeout = (Strings.isNullOrEmpty(LC.get("ldap_abandon_on_timeout")));
/*     */   }
/*     */   
/*     */   public static class ZimbraLdapConfig
/*     */     extends LdapServerConfig
/*     */   {
/*     */     private LdapServerType serverType;
/*     */     private final int connPoolInitSize;
/*     */     
/*     */     public ZimbraLdapConfig(LdapServerType serverType)
/*     */     {
/* 142 */       super();
/*     */       
/* 144 */       this.serverType = serverType;
/* 145 */       this.connPoolInitSize = LC.ldap_connect_pool_initsize.intValue();
/*     */       
/* 147 */       if (LdapServerType.MASTER == this.serverType) {
/* 148 */         this.ldapURLs = getMasterURLs();
/*     */       } else {
/* 150 */         this.ldapURLs = getReplicaURLs();
/*     */       }
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 156 */       this.adminBindDN = LC.zimbra_ldap_userdn.value();
/* 157 */       this.adminBindPassword = LC.zimbra_ldap_password.value();
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 163 */       boolean ldap_starttls_supported = "1".equals(LC.ldap_starttls_supported.value());
/*     */       
/* 165 */       boolean ldap_starttls_required = LC.ldap_starttls_required.booleanValue();
/* 166 */       boolean zimbra_require_interprocess_security = "1".equals(LC.zimbra_require_interprocess_security.value());
/*     */       
/* 168 */       this.wantStartTLS = ((ldap_starttls_supported) && (ldap_starttls_required) && (zimbra_require_interprocess_security));
/*     */       
/* 170 */       this.connType = LdapConnType.getConnType(this.ldapURLs, this.wantStartTLS);
/*     */     }
/*     */     
/*     */     public int getConnPoolInitSize()
/*     */     {
/* 175 */       return this.connPoolInitSize;
/*     */     }
/*     */     
/*     */ 
/*     */     private String getReplicaURLs()
/*     */     {
/* 181 */       String replicaURLs = LC.ldap_url.value().trim();
/* 182 */       if (replicaURLs.length() == 0) {
/* 183 */         String ldapHost = LC.ldap_host.value();
/* 184 */         String ldapPort = LC.ldap_port.value();
/*     */         
/* 186 */         if (StringUtil.isNullOrEmpty(ldapHost)) {
/* 187 */           ldapHost = "localhost";
/*     */         }
/* 189 */         if (StringUtil.isNullOrEmpty(ldapPort)) {
/* 190 */           ldapPort = "389";
/*     */         }
/* 192 */         replicaURLs = "ldap://" + ldapHost + ":" + ldapPort + "/";
/*     */       }
/*     */       
/* 195 */       return replicaURLs;
/*     */     }
/*     */     
/*     */     private String getMasterURLs() {
/* 199 */       String masterURLs = LC.ldap_master_url.value().trim();
/* 200 */       if (masterURLs.length() == 0) {
/* 201 */         masterURLs = getReplicaURLs();
/*     */       }
/* 203 */       return masterURLs;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public static class GenericLdapConfig
/*     */     extends LdapServerConfig.ExternalLdapConfig
/*     */   {
/*     */     public GenericLdapConfig(String[] urls, boolean wantStartTLS, String bindDn, String bindPassword)
/*     */     {
/* 213 */       this(LdapServerConfig.joinURLS(urls), wantStartTLS, bindDn, bindPassword);
/*     */     }
/*     */     
/*     */     public GenericLdapConfig(String urls, boolean wantStartTLS, String bindDn, String bindPassword)
/*     */     {
/* 218 */       super(wantStartTLS, null, bindDn, bindPassword, null, null);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static class ExternalLdapConfig
/*     */     extends LdapServerConfig
/*     */   {
/*     */     protected String derefAliasPolicy;
/*     */     
/*     */ 
/*     */ 
/*     */     private String authMech;
/*     */     
/*     */ 
/*     */     private Set<String> binaryAttrs;
/*     */     
/*     */ 
/*     */     private String notes;
/*     */     
/*     */ 
/*     */ 
/*     */     public ExternalLdapConfig(String urls, boolean wantStartTLS, String authMech, String bindDn, String bindPassword, Set<String> binaryAttrs, String note)
/*     */     {
/* 244 */       super();
/*     */       
/* 246 */       this.ldapURLs = urls;
/* 247 */       this.adminBindDN = bindDn;
/* 248 */       this.adminBindPassword = bindPassword;
/* 249 */       this.wantStartTLS = wantStartTLS;
/*     */       
/* 251 */       this.authMech = authMech;
/* 252 */       this.binaryAttrs = binaryAttrs;
/* 253 */       this.notes = this.notes;
/*     */       
/* 255 */       this.derefAliasPolicy = LC.ldap_deref_aliases.value();
/*     */       
/* 257 */       this.connType = LdapConnType.getConnType(this.ldapURLs, this.wantStartTLS);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     public ExternalLdapConfig(String[] urls, boolean wantStartTLS, String authMech, String bindDn, String bindPassword, Set<String> binaryAttrs, String note)
/*     */     {
/* 273 */       this(LdapServerConfig.joinURLS(urls), wantStartTLS, authMech, bindDn, bindPassword, binaryAttrs, note);
/*     */     }
/*     */     
/*     */     public static class ConnPoolKey
/*     */     {
/*     */       private static final char DELIMITER = ':';
/*     */       
/*     */       public static String getConnPoolKey(LdapServerConfig.ExternalLdapConfig config) {
/* 281 */         StringBuilder key = new StringBuilder();
/* 282 */         key.append(config.ldapURLs + ':');
/* 283 */         key.append(config.connType.toString() + ':');
/* 284 */         key.append((config.authMech == null ? "" : config.authMech) + ':');
/* 285 */         key.append((config.adminBindDN == null ? "" : config.adminBindDN) + ':');
/* 286 */         key.append(config.adminBindPassword == null ? "" : config.adminBindPassword);
/*     */         
/*     */ 
/*     */ 
/*     */ 
/* 291 */         return key.toString();
/*     */       }
/*     */       
/*     */ 
/*     */       public static String getDisplayName(String key)
/*     */       {
/* 297 */         int offset = key.lastIndexOf(':');
/* 298 */         return key.substring(0, offset);
/*     */       }
/*     */     }
/*     */     
/*     */     public String getAuthMech() {
/* 303 */       return this.authMech;
/*     */     }
/*     */     
/*     */     public Set<String> getBinaryAttrs() {
/* 307 */       return this.binaryAttrs;
/*     */     }
/*     */     
/*     */     public String getNotes() {
/* 311 */       return this.notes;
/*     */     }
/*     */     
/*     */     public String getDerefAliasPolicy() {
/* 315 */       return this.derefAliasPolicy;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     public int getConnPoolInitSize()
/*     */     {
/* 328 */       return 0;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public static String joinURLS(String[] urls)
/*     */   {
/* 335 */     if (urls.length == 1) {
/* 336 */       return urls[0];
/*     */     }
/* 338 */     StringBuffer url = new StringBuffer();
/* 339 */     for (int i = 0; i < urls.length; i++) {
/* 340 */       if (i > 0) {
/* 341 */         url.append(' ');
/*     */       }
/* 343 */       url.append(urls[i]);
/*     */     }
/* 345 */     return url.toString();
/*     */   }
/*     */   
/*     */   public String getLdapURL()
/*     */   {
/* 350 */     return this.ldapURLs;
/*     */   }
/*     */   
/*     */   public String getAdminBindDN() {
/* 354 */     return this.adminBindDN;
/*     */   }
/*     */   
/*     */   public String getAdminBindPassword() {
/* 358 */     return this.adminBindPassword;
/*     */   }
/*     */   
/*     */   public boolean getWantStartTLS() {
/* 362 */     return this.wantStartTLS;
/*     */   }
/*     */   
/*     */   public LdapConnType getConnType() {
/* 366 */     return this.connType;
/*     */   }
/*     */   
/*     */   public boolean sslAllowUntrustedCerts() {
/* 370 */     return this.sslAllowUntrustedCerts;
/*     */   }
/*     */   
/*     */   public int getConnPoolMaxSize() {
/* 374 */     return this.connPoolMaxSize;
/*     */   }
/*     */   
/*     */   public int getConnPoolTimeoutMillis() {
/* 378 */     return this.connPoolTimeoutMillis;
/*     */   }
/*     */   
/*     */   public boolean isConnPoolHelathCheckOnCheckoutEnabled() {
/* 382 */     return this.connPoolHelathCheckOnCheckoutEnabled;
/*     */   }
/*     */   
/*     */   public long getConnPoolHelathCheckBackgroundIntervalMillis() {
/* 386 */     return this.connPoolHelathCheckBackgroundIntervalMillis;
/*     */   }
/*     */   
/*     */   public long getConnPoolHelathCheckMaxResponseTimeMillis() {
/* 390 */     return this.connPoolHelathCheckMaxResponseTimeMillis;
/*     */   }
/*     */   
/*     */   public int getConnectTimeoutMillis() {
/* 394 */     return this.connectTimeoutMillis;
/*     */   }
/*     */   
/*     */   public int getReadTimeoutMillis() {
/* 398 */     return this.readTimeoutMillis;
/*     */   }
/*     */   
/*     */   public boolean isAbandonOnTimeout() {
/* 402 */     return this.isAbandonOnTimeout;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/ldap/LdapServerConfig.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */